{layout name="public/layout" /}
{include file='yxnavbar'}
<style>
    .right_btn{
        display: inline-block;
        float: right;
        border: 1px solid #ff4949;
        padding: 4px 8px;
        color: #ff4949;
        font-size: 12px;
        background: #ffeded;
        border-radius: 3px;
    }
</style>


<div class="main">
    {include file='../../plugin/gift/template/web/common_nav'}

    <div class="tab-pane">
      <form id = "myform" action="#" method="post" class="form-horizontal" role="form">
        <div class="panel panel-default" role="tabpanel">
        <div class="panel-heading">基础设置</div>
        <div class="panel-body">
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">礼品时间限制</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        <label class="radio-inline">
                            <input name="is_limit_time" value="1" {if $gift_config['is_limit_time']==1} checked="checked"{/if} type="radio"> 启用
                        </label>
                        <label class="radio-inline">
                            <input name="is_limit_time" value="0" {if $gift_config['is_limit_time']==0} checked="checked"{/if} type="radio"> 禁用
                        </label>
                        <span class="help-block">温馨提示：禁用礼品时间限制后，礼品时间将跟随活动时间</span>
                    </div>
                    {if count($themelist)>1 }
                        <div class="col-xs-12 col-sm-2 col-md-2" style="margin-top: 10px">
                            <select onchange="themeidChange();" class="form-control" name="themeid" id="themeid">
                                {loop $themelist $row}
                                  <option value="{$row['id']}" {if $themeid == $row['id'] }selected="selected"{/if}>{$row['id']} - {php echo mb_substr($row['title'],0,8,'utf-8');}</option>
                                {/loop}
                            </select>
                        </div>
                    {else}
                        <input type="hidden" name="themeid" value="{$themeid}" />
                    {/if}
                </div>
                <div class="form-group" id="limit_time">
                    <label class="col-sm-2 col-xs-12 control-label">礼品时间</label>
                    <div class="col-sm-8 col-xs-12">
                        {php echo view_form_field_daterange('gift_limit_time', array('start'=>$gift_config['limit_start_time'],'end'=>$gift_config['limit_end_time']), true);}
                        <span class="help-block">未到开始时间前端不显示礼品，礼品结束隐藏页面</span>
                    </div>
                </div>

<!--                <div class="form-group">-->
<!--                    <label class="col-sm-2 col-xs-12 control-label">成团礼</label>-->
<!--                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">-->
<!--                        <label class="radio-inline">-->
<!--                            <input name="open_tuan_gift" value="1" {if $gift_config['open_tuan_gift']==1} checked="checked"{/if} type="radio">开启-->
<!--                        </label>-->
<!--                        <label class="radio-inline">-->
<!--                            <input name="open_tuan_gift" value="2" {if $gift_config['open_tuan_gift']==2||!$gift_config['open_tuan_gift']} checked="checked"{/if} type="radio">关闭-->
<!--                        </label>-->
<!--                    </div>-->
<!--                </div>-->

<!--                <div class="form-group">-->
<!--                    <label class="col-sm-2 col-xs-12 control-label">邀请下单</label>-->
<!--                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">-->
<!--                        <label class="radio-inline">-->
<!--                            <input name="open_invite_gift" value="1" {if $gift_config['open_invite_gift']==1} checked="checked"{/if} type="radio">开启-->
<!--                        </label>-->
<!--                        <label class="radio-inline">-->
<!--                            <input name="open_invite_gift" value="2" {if $gift_config['open_invite_gift']==2||!$gift_config['open_invite_gift']} checked="checked"{/if} type="radio">关闭-->
<!--                        </label>-->
<!--                    </div>-->
<!--                </div>-->

<!--                <div class="form-group">-->
<!--                    <label class="col-sm-2 col-xs-12 control-label">邀请助力</label>-->
<!--                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">-->
<!--                        <label class="radio-inline">-->
<!--                            <input name="open_help_gift" value="1" {if $gift_config['open_help_gift']==1} checked="checked"{/if} type="radio">开启-->
<!--                        </label>-->
<!--                        <label class="radio-inline">-->
<!--                            <input name="open_help_gift" value="2" {if $gift_config['open_help_gift']==2||!$gift_config['open_help_gift']} checked="checked"{/if} type="radio">关闭-->
<!--                        </label>-->
<!--                    </div>-->
<!--                </div>-->

<!--                <div id="help_gift">-->
<!--                      <div class="form-group">-->
<!--                         <label class="col-sm-2 col-xs-12 control-label">邀请人身份</label>-->
<!--                         <div class="col-sm-8 col-xs-12">-->
<!--                            <label class="radio-inline">-->
<!--                                <input name="help_invite_identity" value="0" type="radio" {if $gift_config['help_invite_identity']==0||empty($gift_config['help_invite_identity'])}checked{/if}>不限制-->
<!--                            </label>-->
<!--                            <label class="radio-inline">-->
<!--                                <input name="help_invite_identity" value="4" type="radio" {if $gift_config['help_invite_identity']==4}checked{/if}>支付客户-->
<!--                            </label>-->
<!--                         </div>-->
<!--                      </div>-->

<!--                      <div class="form-group">-->
<!--                            <label class="col-sm-2 col-xs-12 control-label">助力规则</label>-->
<!--                            <div class="col-sm-9 col-xs-12">-->
<!--                                <table class='table'>-->
<!--                                    <thead>-->
<!--                                    <tr>-->
<!--                                        <th>条件</th>-->
<!--                                        <th>礼品</th>-->
<!--                                        <th>备注</th>-->
<!--                                        <th>状态</th>-->
<!--                                        <th>操作</th>-->
<!--                                    </tr>-->
<!--                                    </thead>-->
<!--                                    <tbody id="help_gift_data">-->
<!--                                    {if $help_gift}-->
<!--                                        {loop $help_gift $help}-->
<!--                                            <tr>-->
<!--                                                <input type="hidden" name="help_taskid[]" value="{$help['taskid']}">-->
<!--                                                <td class="col-sm-2 col-xs-12">-->
<!--                                                    <input name="help_gift_num[]" min="1"  value="{$help['number']}" type="number" style="width:40%;display: inline-block;" class="form-control span3"/>人助力-->
<!--                                                </td>-->
<!--                                                <td class="col-sm-3 col-xs-12">-->
<!--                                                    <select class="form-control" name="help_gift_id[]">-->
<!--                                                        {loop $gift_list $i $item}-->
<!--                                                         <option value="{$i}" {if $i==$help['gift_id']} selected {/if}>{$item['name']}</option>-->
<!--                                                        {/loop}-->
<!--                                                    </select>-->
<!--                                                </td>-->
<!--                                                <td class="col-sm-3 col-xs-12">-->
<!--                                                    <input name="help_gift_remark[]"  value="{$help['remark']}"  class="form-control span3"/>-->
<!--                                                </td>-->
<!--                                                <td class="col-sm-1 col-xs-12">-->
<!--                                                    <select class="form-control" name="help_gift_status[]">-->
<!--                                                        <option value="1" {if $help['status']==1} selected {/if}>上架</option>-->
<!--                                                        <option value="2" {if $help['status']==2} selected {/if}>下架</option>-->
<!--                                                    </select>-->
<!--                                                </td>-->
<!--                                                <td class="col-sm-1 col-xs-12">-->
<!--                                                    <a href='javascript:;'  onclick="removeGiftItem(this,'help_gift',{$help['taskid']})"><i class='glyphicon glyphicon-remove'></i> 删除</a>-->
<!--                                                </td>-->
<!--                                            </tr>-->
<!--                                        {/loop}-->
<!--                                    {else}-->
<!--                                        <tr>-->
<!--                                            <td class="col-sm-2 col-xs-12">-->
<!--                                                <input name="help_gift_num[]" min="1"  type="number" style="width:40%;display: inline-block;" class="form-control span3" value=""/>人助力-->
<!--                                            </td>-->
<!--                                            <td class="col-sm-3 col-xs-12">-->
<!--                                                <select class="form-control" name="help_gift_id[]">-->
<!--                                                    {loop $gift_list $i $item}-->
<!--                                                    <option value="{$i}">{$item['name']}</option>-->
<!--                                                    {/loop}-->
<!--                                                </select>-->
<!--                                            </td>-->
<!--                                            <td class="col-sm-3 col-xs-12">-->
<!--                                                <input name="help_gift_remark[]"  value=""  class="form-control span3"/>-->
<!--                                            </td>-->
<!--                                            <td class="col-sm-1 col-xs-12">-->
<!--                                                <select class="form-control" name="help_gift_status[]">-->
<!--                                                    <option value="1">上架</option>-->
<!--                                                    <option value="2">下架</option>-->
<!--                                                </select>-->
<!--                                            </td>-->
<!--                                            <td class="col-sm-1 col-xs-12">-->
<!--                                                <a href='javascript:;'  onclick="removeGiftItem(this,'help_gift',0)"><i class='glyphicon glyphicon-remove'></i> 删除</a>-->
<!--                                            </td>-->
<!--                                        </tr>-->
<!--                                    {/if}-->
<!--                                    </tbody>-->
<!--                                </table>-->
<!--                                <a href="javascript:;" onclick="addHelpGiftItem();"><i class="glyphicon glyphicon-plus" title="添加邀请助力规则"></i>添加邀请助力规则</a>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-2 col-xs-12 control-label">助力收集客资</label>-->
<!--                            <div class="col-sm-8 col-xs-12">-->
<!--                                <label class="radio-inline">-->
<!--                                    <input name="collect_help_user_info" value="1" type="radio" {if $gift_config['collect_help_user_info']==1}checked{/if}>收集-->
<!--                                </label>-->
<!--                                <label class="radio-inline">-->
<!--                                    <input name="collect_help_user_info" value="2" type="radio" {if $gift_config['collect_help_user_info']==2||empty($gift_config['collect_help_user_info'])}checked{/if}>不收集-->
<!--                                </label>-->
<!--                            </div>-->
<!--                        </div>-->

<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-2 col-xs-12 control-label">最大助力次数</label>-->
<!--                            <div class="col-sm-8 col-md-4 col-xs-12">-->
<!--                                <div class="input-group">-->
<!--                                    <span class="input-group-addon"> 活动期间，单个用户最多能给</span>-->
<!--                                    <input name="help_user_num" type="number" min="0"  max="9999" value="{$tuan['help_user_num']}"  class="form-control"/>-->
<!--                                    <span class="input-group-addon">人助力</span>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                </div>-->

                <div class="form-group">
                    <input type="hidden" name="id" value="{$item['id']}">
                    <input type="hidden" name="themeid" value="{$themeid}">
                    <label class="col-sm-2 col-xs-12 control-label">展示位置</label>
                    <div class="col-sm-8 col-md-8 col-lg-8 col-xs-12">
                        <label class="radio-inline">
                            <input name="show_mode" value="1" {if $gift_config['show_mode']==1||empty($gift_config['show_mode'])}checked{/if} type="radio">头像下方显示
                        </label>
                        <label class="radio-inline">
                            <input name="show_mode" value="2" {if $gift_config['show_mode']==2}checked{/if} type="radio">中间显示
                        </label>
                        <label class="radio-inline">
                            <input name="show_mode" value="3" {if $gift_config['show_mode']==3}checked{/if} type="radio">底部显示
                        </label>
                        <label class="radio-inline">
                            <input name="show_mode" value="4" {if $gift_config['show_mode']==4}checked{/if} type="radio">右侧浮标+弹出层
                        </label>
                    </div>
                </div>
                <div class="form-group" id="buoy_img" style="display: none">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">右侧浮标图片</label>
                    <div class="col-sm-8 col-xs-12">
                        {php echo view_form_field_image('buoy_img',$gift_config['buoy_img']);}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">兑换礼品模式</label>
                    <div class="col-sm-8 col-xs-12">
                        <label class="radio-inline">
                            <input name="exchange_mode" value="1" type="radio" {if $gift_config['exchange_mode']==1}checked{/if}>实物礼品仅可选择一个兑换
                        </label>
                        <label class="radio-inline">
                            <input name="exchange_mode" value="2" type="radio" {if $gift_config['exchange_mode']==2||empty($gift_config['exchange_mode'])}checked{/if}>实物礼品可选择全部兑换
                        </label>
                    </div>
                </div>

        </div>
    </div>
        <div class="panel panel-default" role="tabpanel">
            <div class="panel-heading">成团礼</div>
            <div class="panel-body">
                <div class="form-group">
                    <div class="col-sm-12 col-xs-12">
                        <table class='table'>
                            <thead>
                            <tr>
                                <th>条件</th>
                                <th>礼品</th>
                                <th>身份</th>
                                <th>备注</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="tuan_gift_data">
                            {loop $tuan_gift $tuan}
                            <tr>
                                <input type="hidden" name="tuan_taskid[]" value="{$tuan['taskid']}">
                                <td class="col-sm-2 col-xs-12">
                                    <input name="tuan_gift_num[]" type="number" min="1"  value="{$tuan['number']}" style="width:40%;display: inline-block;" class="form-control span3"/>人成团
                                </td>
                                <td class="col-sm-3 col-xs-12">
                                    <select class="form-control" name="tuan_gift_id[]">
                                        {loop $gift_list $i $item}
                                        <option value="{$i}" {if $i==$tuan['gift_id']} selected {/if}>{$item['name']}</option>
                                        {/loop}
                                    </select>
                                </td>
                                <td class="col-sm-2 col-xs-12">
                                    <select class="form-control" name="tuan_gift_rule[]">
                                        <option value="1" {if $tuan['identity']==1} selected {/if}>团长</option>
                                        <option value="3" {if $tuan['identity']==3} selected {/if}>团员</option>
                                        <option value="2" {if $tuan['identity']==2} selected {/if}>仅限支付客户</option>
                                    </select>
                                </td>
                                <td class="col-sm-3 col-xs-12">
                                    <input name="tuan_gift_remark[]"  value="{$tuan['remark']}"  class="form-control span3"/>
                                </td>
                                <td class="col-sm-1 col-xs-12">
                                    <select class="form-control" name="tuan_gift_status[]">
                                        <option value="1" {if $tuan['status']==1} selected {/if}>上架</option>
                                        <option value="2" {if $tuan['status']==2} selected {/if}>下架</option>
                                    </select>
                                </td>
                                <td  class="col-sm-1 col-xs-12">
                                    <a href='javascript:;' data-classify="tuan_gift" data-taskid="{$tuan['taskid']}" onclick="removeGiftItem(this,'tuan_gift',{$tuan['taskid']})"><i class='glyphicon glyphicon-remove'></i> 删除</a>
                                </td>
                            </tr>
                            {/loop}
                            </tbody>
                        </table>
                        <a href="javascript:;" onclick="addTuanGiftItem();"><i class="glyphicon glyphicon-plus" title="添加规则"></i>添加成团礼规则</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="panel panel-default" role="tabpanel">
            <div class="panel-heading">邀请下单</div>
            <div class="panel-body">
                <div class="form-group">
                    <div class="col-sm-12 col-xs-12">
                        <table class='table'>
                            <thead>
                            <tr>
                                <th>条件</th>
                                <th>礼品</th>
                                <th>身份</th>
                                <th>备注</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="invite_gift_data">
                            {loop $invite_gift $invite}
                            <tr>
                                <input type="hidden" name="invite_taskid[]" value="{$invite['taskid']}">
                                <td class="col-sm-2 col-xs-12">
                                    <input name="invite_gift_num[]" min="1"  value="{$invite['number']}" type="number" style="width:40%;display: inline-block;" class="form-control span3"/>人下单
                                </td>
                                <td class="col-sm-3 col-xs-12">
                                    <select class="form-control" name="invite_gift_id[]">
                                        {loop $gift_list $i $item}
                                        <option value="{$i}" {if $i==$invite['gift_id']} selected {/if}>{$item['name']}</option>
                                        {/loop}
                                    </select>
                                </td>
                                <td class="col-sm-2 col-xs-12">
                                    <select class="form-control" name="invite_gift_rule[]">
                                        <option value="0" {if $invite['identity']==0}selected{/if}>不限制</option>
                                        <option value="1" {if $invite['identity']==1}selected{/if}>团长</option>
                                        <option value="3" {if $invite['identity']==3}selected{/if}>团员</option>
                                        <option value="4" {if $invite['identity']==4}selected{/if}>仅限支付客户</option>
                                    </select>
                                </td>
                                <td class="col-sm-3 col-xs-12">
                                    <input name="invite_gift_remark[]"  value="{$invite['remark']}"  class="form-control span3"/>
                                </td>
                                <td class="col-sm-1 col-xs-12">
                                    <select class="form-control" name="invite_gift_status[]">
                                        <option value="1" {if $invite['status']==1} selected {/if}>上架</option>
                                        <option value="2" {if $invite['status']==2} selected {/if}>下架</option>
                                    </select>
                                </td>
                                <td class="col-sm-1 col-xs-12">
                                    <a href='javascript:;'  onclick="removeGiftItem(this,'invite_gift',{$invite['taskid']})"><i class='glyphicon glyphicon-remove'></i> 删除</a>
                                </td>
                            </tr>
                            {/loop}
                            </tbody>
                        </table>
                        <a href="javascript:;" onclick="addInviteGiftItem();"><i class="glyphicon glyphicon-plus" title="添加邀请礼规则"></i>添加邀请下单规则</a>
                    </div>
                </div>
           </div>
        </div>
        <div class="form-group" id="sub_upload" >
            <div class="col-sm-12">
                <input name="submit"  onclick="addOrEditItem()"  type="button" value="提交" class="btn btn-primary col-lg-2">
            </div>
        </div>
     </form>
</div>

<script>
    let is_new_wxapp_version = "{php echo $is_new_wxapp_version;}";
    let softmode = "{php echo $system['softmode'];}";
    $(document).ready(function (){
        if (softmode!=0&&!is_new_wxapp_version){
            layer.confirm('当前绑定小程序不是新版本，请选择新版本小程序或更换活动后台', {
                title: "邀请礼配置提示",
                icon: 0,
                btn: ['已知晓'],
                btnAlign: "r",
            }, function(index, layero){
            });
        }
        var limit_time = $('input[name="is_limit_time"]:checked').val();
        timeShowOrHide(limit_time);
        //默认隐藏和显示
        var tuan_gift = $('input[name="open_tuan_gift"]:checked').val();
        giftConfigShowOrHide('tuan_gift',tuan_gift);
        var invite_gift = $('input[name="open_invite_gift"]:checked').val();
        giftConfigShowOrHide('invite_gift',invite_gift);
        var help_gift = $('input[name="open_help_gift"]:checked').val();
        giftConfigShowOrHide('help_gift',help_gift);
    });



    function editGiftItem(id){
            let postUrl = "{php echo createWebUrlPlugin('gift.config.editGift',array('themeid'=>$themeid));}";
            $.ajax({
                url:postUrl+"&id="+id,
                dataType:'json',
                method:'get',
                success:function (e) {
                    let status = e.status;
                    let result = e.result;
                    let data = result.data;
                    if(status==1){
                        $('#shangjiaid').val(data.shangjiaid);
                        $("#id").val(data.id);
                        $("#name").val(data.name);
                        $(".img-responsive").attr("src",data.top_img);
                        $("#price").val(data.price);
                        $("[name='top_img']").val(data.top_img);
                        $(`input[name='type'][value=${data.type}]`).attr('checked','true');
                        $(`input[name='status'][value=${data.status}]`).attr('checked','true');
                        var index = layer.open({
                            type:1,
                            title:['编辑礼品','font-size:18px;'],
                            area:'700px',
                            zIndex:2,
                            content:$('#show_form')
                        });
                    }else{
                        layer.msg(result.msg);
                    }
                },
                fail:function (err) {
                    console.log(err);
                }
            });
    }

    function addTuanGiftItem() {
        var html = `<tr>
                          <td class="col-sm-2 col-xs-12"> <input name="tuan_gift_num[]" min="1" type="number" style="width:40%;display: inline-block;" class="form-control span3" value=""/>人成团</td>'
                          <td class="col-sm-3 col-xs-12">
                               <select class="form-control" name="tuan_gift_id[]">
                                        {loop $gift_list $i $item}
                                           <option value="{$i}">{$item['name']}</option>
                                        {/loop}
                               </select>
                          </td>
                          <td class="col-sm-2 col-xs-12">
                               <select class="form-control" name="tuan_gift_rule[]">
                                   <option value="1" >团长</option>
                                   <option value="3" >团员</option>
                                   <option value="2" >仅限支付客户</option>
                              </select>
                          </td>
                           <td class="col-sm-3 col-xs-12">
                                    <input name="tuan_gift_remark[]"   class="form-control span3"/>
                           </td>
                            <td class="col-sm-1 col-xs-12">
                               <select class="form-control" name="tuan_gift_status[]">
                                   <option value="1">上架</option>
                                   <option value="2">下架</option>
                               </select>
                           </td>
                           <td >
                              <a href="javascript:;" data-taskid="0" data-classify="tuan_gift" onclick="removeGiftItem(this,'tuan_gift',0)" ><i class="glyphicon glyphicon-remove"></i> 删除</a>
                           </td>
                   </tr>`;
        $("#tuan_gift_data").append(html);
    }

    function addInviteGiftItem(){
        var html = `<tr>
                      <td class="col-sm-2 col-xs-12"><input name="invite_gift_num[]" min="1" type="number" style="width:40%;display: inline-block;" class="form-control span3" value=""/>人下单</td>
                      <td class="col-sm-3 col-xs-12">
                          <select class="form-control" name="invite_gift_id[]">
                                   {loop $gift_list $i $item}
                                         <option value="{$i}">{$item['name']}</option>
                                  {/loop}
                          </select>
                      </td>
                      <td class="col-sm-2 col-xs-12">
                                <select class="form-control" name="invite_gift_rule[]">
                                    <option value="0" >不限制</option>
                                    <option value="1" >团长</option>
                                    <option value="3" >团员</option>
                                    <option value="4" >仅限支付客户</option>
                                </select>
                      </td>';
                      <td class="col-sm-3 col-xs-12">
                                <input name="invite_gift_remark[]"   class="form-control span3"/>
                      </td>
                       <td class="col-sm-1 col-xs-12">
                               <select class="form-control" name="invite_gift_status[]">
                                   <option value="1">上架</option>
                                   <option value="2">下架</option>
                               </select>
                           </td>
                      <td><a href="javascript:;" data-taskid="0" data-classify="invite_gift" onclick="removeGiftItem(this,'invite_gift',0)" ><i class="glyphicon glyphicon-remove"></i>删除</a></td>
                    </tr>`;
        $("#invite_gift_data").append(html);
    }

    function addHelpGiftItem(){
        var html = `<tr>
                      <td class="col-sm-2 col-xs-12"><input name="help_gift_num[]" min="1" type="number" style="width:40%;display: inline-block;" class="form-control span3" value=""/>人助力</td>
                      <td class="col-sm-3 col-xs-12">
                          <select class="form-control" name="help_gift_id[]">
                                   {loop $gift_list $i $item}
                                         <option value="{$i}">{$item['name']}</option>
                                  {/loop}
                          </select>
                      </td>
                      <td class="col-sm-3 col-xs-12">
                                <input name="help_gift_remark[]"   class="form-control span3"/>
                      </td>

                       <td class="col-sm-1 col-xs-12">
                               <select class="form-control" name="help_gift_status[]">
                                   <option value="1">上架</option>
                                   <option value="2">下架</option>
                               </select>
                           </td>
                      <td><a href="javascript:;" data-taskid="0" data-classify="invite_gift" onclick="removeGiftItem(this,'help_gift',0)" ><i class="glyphicon glyphicon-remove"></i>删除</a></td>
                    </tr>`;
        $("#help_gift_data").append(html);
    }

    $("[name='is_limit_time']").change(function () {
        var val = $(this).val();
        timeShowOrHide(val);
    })
    //时间隐藏显示
    function timeShowOrHide(val){
        if(val==1){
            $('#limit_time').show();
        }else{
            $('#limit_time').hide();
        }
    }
    $("[name='show_mode']").change(function () {
        var val = $(this).val();
        console.log(val)
        if(val==4){
            $('#buoy_img').show();
        }else{
            $('#buoy_img').hide();
        }
    });
    //配置礼品的隐藏显示
    $("[name='open_tuan_gift']").change(function () {
        var val = $(this).val();
        if(val==2){
            checkOffGift('tuan_gift',val);
        }else{
            giftConfigShowOrHide('tuan_gift',val);
        }
    });

    $("[name='open_invite_gift']").change(function () {
        var val = $(this).val();
        if(val==2){
            checkOffGift('invite_gift',val);
        }else{
            giftConfigShowOrHide('invite_gift',val);
        }
    });

    $("[name='open_help_gift']").change(function () {
        var val = $(this).val();
        if(val==2){
            checkOffGift('help_gift',val);
        }else{
            giftConfigShowOrHide('help_gift',val);
        }
    });

    function giftConfigShowOrHide(target,val){
        if(val==1){
            $('#'+target).show();
        }else{
            $('#'+target).hide();
        }
    }

    $('#themeid').change(function () {
        var val = $(this).val();
        location.href = "{php echo createWebUrlPlugin('gift.config');}&themeid="+val;
    });

    function removeGiftItem(obj,classify,taskid) {
        if(taskid){
            let postUrl = "{php echo createWebUrlPlugin('gift.config.deleteGift',array('themeid'=>$themeid));}";
            let formData = {
                classify:classify,
                taskid: taskid
            };
            $.ajax({
                url:postUrl,
                dataType:'json',
                method:'post',
                data:formData,
                success:function (e) {
                    let status = e.status;
                    let result = e.result;
                    layer.msg(result.msg);
                    if (status==1){
                        $(obj).parent().parent().remove()
                    }
                },
                fail:function (err) {
                    console.log(err);
                }
            });
        }else{
            $(obj).parent().parent().remove()
        }
    }

    function addOrEditItem() {
        let postUrl = "{php echo createWebUrlPlugin('gift.config',array('themeid'=>$themeid));}";
        let formData = $("#myform").serialize();
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                let status = e.status;
                let result = e.result;
                layer.msg(result.msg);
                if (status==1){
                    location.reload();
                }
            },
            fail:function (err) {
                console.log(err);
            }
        });
    }

    function checkOffGift(classify,val){
        let postUrl = "{php echo createWebUrlPlugin('gift.config.checkOffGiftConfig',array('themeid'=>$themeid));}";
        let formData = {
            classify:classify
        }
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                let status = e.status;
                let result = e.result;
                if (status==1){
                    giftConfigShowOrHide(classify,val);
                }else{
                    layer.msg(result.msg);
                }
            },
            fail:function (err) {
                console.log(err);
            }
        });
    }

</script>